// 中文字两个字节
jQuery.validator.addMethod("byteRangeLength", function(value, element, param) {
    var length = value.length;
    for(var i = 0; i < value.length; i++){
        if(value.charCodeAt(i) > 127){
            length++;
        }
    }
  return this.optional(element) || ( length >= param[0] && length <= param[1] );   
}, $.validator.format("请确保输入的值在{0}-{1}个字节之间(一个中文字算2个字节)"));


// 邮政编码验证   
jQuery.validator.addMethod("isZipCode", function(value, element) {   
    var tel = /^[0-9]{6}$/;
    return this.optional(element) || (tel.test(value));
}, "请正确填写您的邮政编码");

// 用户名验证   
jQuery.validator.addMethod("isUserName", function(value, element) {   
	var tel = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
	return this.optional(element) || (tel.test(value));
}, "由字母数字下划线组成，且以字母和下划线开头");

//手机号码验证 
jQuery.validator.addMethod("isMobile", function(value, element) {
	var length = value.length;
	var mobile = /^1[358]\d{9}$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
}, "请输入正确的手机号码");

// 电话号码验证 
jQuery.validator.addMethod("isTel",	function(value, element) {
	var tel = /^((\d{3,4})-)(\d{7,8})(-(\d{3,}))?$/;
	return this.optional(element) || (tel.test(value));
}, "请输入正确的电话号码, 如 <i class=\"green\">010-12345678-0001</i>");

//用户名只允许为英文，数字和汉字的混合,/n请检查是否前后有空格或者其他符号"
jQuery.validator.addMethod("isText", function(value, element) {
	var tel =  /^(\w|[\u4E00-\u9FA5])*$/;
	return this.optional(element) || (tel.test(value));
}, "不允许有空格或其他符号");

jQuery.validator.addMethod("notBlank", function(value, element) {
	var tel =  /^[^ ]+$/;
	return this.optional(element) || (tel.test(value));
}, "不允许有空格");
